package com.hotel.controllers;

import com.hotel.entitys.Dept;
import com.hotel.entitys.RestPOJO;
import com.hotel.entitys.Room;
import com.hotel.services.RoomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author chend
 * @time 2022/02/28 11:52:09
 */
@RestController
@Api(tags="房态管理接口")//tags:说明信息
public class RoomController {
    @Autowired
    private RoomService roomService ;


    @ApiOperation(
            value = "查询所有房间",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/room")
    public RestPOJO selAllRoom(){
        List<Room> roomList =  roomService.selAllRoom();
        RestPOJO restPOJO = new RestPOJO();
        if (roomList.size()>=0){
            restPOJO.setMessage("查询成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(roomList);
        }else {
            restPOJO.setMessage("查询失败");
            restPOJO.setStatus(1001);
        }
       return restPOJO ;
    }

    @ApiOperation(
            value = "修改房间状态",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping  ("/setStatus")
    public RestPOJO setStatus(Integer room_id,Integer room_status){
           Integer i  = roomService.setStatus(room_id,room_status);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("修改成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("修改失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }


    @ApiOperation(
            value = "搜索框按照预定人电话或姓名查询房间",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/room/search/{keyword}")
    public RestPOJO selRoomByName(@PathVariable("keyword") String keyword){
        System.out.println(keyword);
        List<Room> roomList = roomService.selRoomByNameorPhone(keyword);
        System.out.println(roomList);
        RestPOJO restPOJO = new RestPOJO();
        if (roomList.size()>=0){
            restPOJO.setMessage("查询成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(roomList);
        }else {
            restPOJO.setMessage("查询失败");
            restPOJO.setStatus(1001);
            restPOJO.setData(roomList);
        }
        return restPOJO ;
    }



    //查询框查询所有房间信息
    @ApiOperation(
            value = "按照房间类型或房间状态查询",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/rooms")
    public RestPOJO getAll(String typeCheck,String statusCheck) {
        RestPOJO restPOJO = new RestPOJO();
        List<Room> l = roomService.getAllRooms(typeCheck,statusCheck);
        if (l.size() > 0) {
            restPOJO.setMessage("查询成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(l);
        } else {
            restPOJO.setMessage("查询失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }
}
